﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;

namespace WpfApplication1.tools
{
    public class cPencil
    {
        public Point currentPoint = new Point(0, 0);
        public bool selected = false;
        public Color brushColor;
        public int brushThickness = 1;

        //sets brush position to mouse position
        public void MouseDown(Point newPosition)
        {
                currentPoint = newPosition;
        }

        //if pencil is selected and brush color is not null (it is not null all the time since before performing
        //mouseMove we perform mouseDown where we predefine brushColor attribute to colorPicker
        public void MouseMove(Point newPosition, Canvas canvas1)
        {
            if (selected && brushColor!=null)
            {
                //Approach 2
                //tried to make it this way because once the thickness of line increases it doesn't look good.
                //instead of being connected lines looks like |||||| especially on turns.
                //so far this approach doesn't solve the problem.
                Path linePath = new Path();
                linePath.Stroke = new SolidColorBrush(brushColor);
                linePath.StrokeThickness = brushThickness;
                linePath.Fill = new SolidColorBrush(brushColor);

                LineGeometry line = new LineGeometry();
                line.StartPoint = new Point(currentPoint.X, currentPoint.Y);
                line.EndPoint = new Point(newPosition.X, newPosition.Y);

                linePath.Data = line;
                //original approach 1
                //line.Stroke = new SolidColorBrush(brushColor);
                ////manipulate lines thickness
                //line.StrokeThickness = brushThickness;
                //line.X1 = currentPoint.X;
                //line.Y1 = currentPoint.Y;
                //line.X2 = newPosition.X;
                //line.Y2 = newPosition.Y;

                //line.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);

                canvas1.Children.Add(linePath);

                currentPoint = newPosition;
            }
        }
    }
}
